-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathDomainCreditRedemptionSuccessViewController.swift
66 lines (57 loc) · 3.18 KB
/
DomainCreditRedemptionSuccessViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import UIKit
protocol DomainCreditRedemptionSuccessViewControllerDelegate: class {
func continueButtonPressed()
}
/// Displays messaging after user successfully redeems domain credit.
class DomainCreditRedemptionSuccessViewController: UIViewController {
private let domain: String
private weak var delegate: DomainCreditRedemptionSuccessViewControllerDelegate?
init(domain: String, delegate: DomainCreditRedemptionSuccessViewControllerDelegate) {
self.domain = domain
self.delegate = delegate
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
let attributedSubtitleConfiguration: NoResultsViewController.AttributedSubtitleConfiguration = {
[weak self] attributedText in
guard let domain = self?.domain else {
return nil
}
return self?.applyDomainStyle(to: attributedText, domain: domain)
}
let controller = NoResultsViewController.controllerWith(title: NSLocalizedString("Congratulations", comment: "Title on domain credit redemption success screen"),
buttonTitle: NSLocalizedString("Continue", comment: "Action title to dismiss domain credit redemption success screen"),
attributedSubtitle: generateDomainDetailsAttributedString(domain: domain),
attributedSubtitleConfiguration: attributedSubtitleConfiguration,
image: "wp-illustration-domain-credit-success")
controller.delegate = self
addChild(controller)
view.addSubview(controller.view)
controller.didMove(toParent: self)
}
private func applyDomainStyle(to attributedString: NSAttributedString, domain: String) -> NSAttributedString? {
let newAttributedString = NSMutableAttributedString(attributedString: attributedString)
let range = (newAttributedString.string as NSString).localizedStandardRange(of: domain)
guard range.location != NSNotFound else {
return nil
}
let font = WPStyleGuide.fontForTextStyle(.body, fontWeight: .semibold)
newAttributedString.setAttributes([.font: font, .foregroundColor: UIColor.text],
range: range)
return newAttributedString
}
private func generateDomainDetailsAttributedString(domain: String) -> NSAttributedString {
let string = String(format: NSLocalizedString("your new domain %@ is being set up. Your site is doing somersaults in excitement!", comment: "Details about recently acquired domain on domain credit redemption success screen"), domain)
let attributedString = NSMutableAttributedString(string: string)
return attributedString
}
}
extension DomainCreditRedemptionSuccessViewController: NoResultsViewControllerDelegate {
func actionButtonPressed() {
delegate?.continueButtonPressed()
}
}